package com.example.SocialApplication;

import android.app.Application;
import android.util.Log;

import java.util.HashMap;
import java.util.Map;

public class Daemon extends Application {

    private static Map<String, Object> map = new HashMap<String, Object>();

    @Override
    public void onCreate() {
        super.onCreate();
        HelperFactory.setHelper(getApplicationContext());
    }

    public static <T> T get(String key, Class<T> t) {
        try {
            return t.cast(map.get(key));
        } catch (Throwable e) {
            Log.w("CacheManager", "cannot cast class", e);
            return null;
        }
    }

    public static void add(String key, Object val) {
        map.put(key, val);
    }

    public static void remove(String key) {
        map.remove(key);
    }

    @Override
    public void onTerminate() {
        HelperFactory.releaseHelper();
        super.onTerminate();
    }
}
